package cn.mw.cmdb.virtualization.dto;

import cn.mw.cmdb.entity.InstanceInfo;
import cn.mw.cmdb.virtualization.annotations.VirtualizationAlias;
import cn.mw.cmdb.virtualization.constant.MwVirtualizationConstant;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;

/**
 * @author gengjb
 * @description 虚拟化基础数据DTO
 * @date 2024/6/26 16:51
 */
@Getter
@Setter
@Schema(name = "VirtualizationBaseDto", description = "虚拟化基础数据DTO")
public class VirtualizationBaseDto implements Serializable {

    private static final long serialVersionUID = 1L;

    private String name;

    private String ipAddress;

    private String instanceId;

    private String hostId;

    private String type;

    @Schema(description = "操作系统")
    private String operateSystem;


    public void extractFrom(InstanceInfo instanceInfo){
        this.name = instanceInfo.getInstanceName();
        this.ipAddress = instanceInfo.getInBandIp();
        this.instanceId = instanceInfo.getId();
        Map<String, Object> infoData = instanceInfo.getData();
        if(infoData != null && infoData.containsKey(MwVirtualizationConstant.TYPE_ID) && infoData.get(MwVirtualizationConstant.TYPE_ID) != null){
            this.hostId = (String) infoData.get(MwVirtualizationConstant.TYPE_ID);
        }
        if(infoData != null && infoData.containsKey(MwVirtualizationConstant.VM_TYPE) && infoData.get(MwVirtualizationConstant.VM_TYPE) != null){
            this.type = (String) infoData.get(MwVirtualizationConstant.VM_TYPE);
        }
        if(infoData != null && infoData.containsKey(MwVirtualizationConstant.OPERATE_SYSTEM) && infoData.get(MwVirtualizationConstant.OPERATE_SYSTEM) != null){
            this.operateSystem = (String) infoData.get(MwVirtualizationConstant.OPERATE_SYSTEM);
        }
    }
}
